#pragma once

#include <vector>
#include <string>
#include <ctemplate/template.h>
#include "oj_model_mysql.hpp"
// #include "oj_model.hpp"

namespace ns_view
{
    using namespace ns_model;

    const std::string questionPath="./template_html/";
    class View
    {
    public:
        View() {}
        ~View() {}

    public:
        void AllExpand(std::vector<Question> &questions,std::string* html)
        {
            const std::string path=questionPath+"all_questions.html";

            ctemplate::TemplateDictionary root("all_questions");
            for(const auto& q:questions)
            {
                ctemplate::TemplateDictionary* sub=root.AddSectionDictionary("question_list");
                sub->SetValue("number",q.number);
                sub->SetValue("title",q.title);
                sub->SetValue("star",q.star);
            }
            ctemplate::Template* tpl=ctemplate::Template::GetTemplate(path,ctemplate::DO_NOT_STRIP);

            tpl->Expand(html,&root);
        }
        void OneExpand(Question& q,std::string* html)
        {
            const std::string path=questionPath+"one_question.html";

            ctemplate::TemplateDictionary root("onequestion");
            root.SetValue("number",q.number);
            root.SetValue("title",q.title);
            root.SetValue("star",q.star);
            root.SetValue("describe",q.desc);
            root.SetValue("code",q.head);

            ctemplate::Template* tpl=ctemplate::Template::GetTemplate(path,ctemplate::DO_NOT_STRIP);
            tpl->Expand(html,&root);
        }
    };
}